/**
 * Created with IntelliJ IDEA.
 * User: Dimas
 * Date: 19.02.13
 * Time: 18:03
 * To change this template use File | Settings | File Templates.
 */
import java.sql.*;
import java.util.Properties;

public class TEDatabase {
    public static Connection connection;


    public void getConnection(){
        Properties properties=new Properties();
        properties.setProperty("useUnicode","true");
        properties.setProperty("characterEncoding","UTF-8");
        properties.setProperty("user","admin_te");
        properties.setProperty("password","adminexp");
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tradexpert", properties);
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

    }

    public static ResultSet execQuery(String query){
        ResultSet result = null;

        try {
            Statement stmt = connection.createStatement();

            result = stmt.executeQuery(query);
        }catch (SQLException e) {
             e.printStackTrace();
        }

        return result;
    }

    public static void updateDB (String query) throws SQLException {
        PreparedStatement updateData = connection.prepareStatement(query);
        updateData.executeUpdate();
        updateData.close();
    }
}
